/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cstdio>
#include <gtest/gtest.h>

#include "define_multimodal.h"
#include "input_device_manager.h"
#include "input_windows_manager_mock.h"
#include "libinput_mock.h"
#include "touch_transform_processor.h"

namespace OHOS {
namespace MMI {
using namespace testing;
using namespace testing::ext;

class TouchTransformProcessorTestWithMock : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
};

void TouchTransformProcessorTestWithMock::SetUpTestCase()
{}

void TouchTransformProcessorTestWithMock::TearDownTestCase()
{}

void TouchTransformProcessorTestWithMock::SetUp()
{}

void TouchTransformProcessorTestWithMock::TearDown()
{}

/**
 * @tc.name: TouchTransformProcessorTest_OnEventTouchDown_001
 * @tc.desc: Test the funcation OnEventTouchDown
 * @tc.type: FUNC
 * @tc.require:
 */
HWTEST_F(TouchTransformProcessorTestWithMock, OnEventTouchDown_001, TestSize.Level1)
{
    libinput_event_touch event {};
    struct libinput_device dev {};
    NiceMock<LibinputInterfaceMock> libinputMock;
    EXPECT_CALL(libinputMock, GetEventType).WillOnce(Return(LIBINPUT_EVENT_TOUCH_DOWN));
    EXPECT_CALL(libinputMock, GetSensorTime).WillOnce(Return(1));
    EXPECT_CALL(libinputMock, GetTouchEvent).WillOnce(Return(&event));
    EXPECT_CALL(libinputMock, GetDevice).WillOnce(Return(&dev));
    EXPECT_CALL(libinputMock, TouchEventGetTime).WillOnce(Return(2));
    EXPECT_CALL(libinputMock, TouchEventGetPressure).WillOnce(Return(1.0));
    EXPECT_CALL(libinputMock, TouchEventGetSeatSlot).WillOnce(Return(1));
    EXPECT_CALL(libinputMock, TouchEventGetContactLongAxis).WillOnce(Return(1));
    EXPECT_CALL(libinputMock, TouchEventGetContactShortAxis).WillOnce(Return(1));
    EXPECT_CALL(libinputMock, TouchEventGetToolType).WillOnce(Return(-1));
    EXPECT_CALL(libinputMock, TouchEventGetBtnToolTypeDown).WillOnce(Return(PointerEvent::TOOL_TYPE_FINGER));

    EXPECT_CALL(*WIN_MGR_MOCK, TouchPointToDisplayPoint).WillOnce(Return(true));
    EXPECT_CALL(*WIN_MGR_MOCK, UpdateTargetPointer).WillOnce(Return(RET_OK));

    int32_t deviceId = 6;
    TouchTransformProcessor processor(deviceId);
    auto pointerEvent = processor.OnEvent(&event.base);
    ASSERT_TRUE(pointerEvent != nullptr);
    EXPECT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
    EXPECT_EQ(pointerEvent->GetPointerAction(), PointerEvent::POINTER_ACTION_DOWN);
}
} // namespace MMI
} // namespace OHOS